import { Router } from 'express'
import { modelService } from '../services/model.js'
import logger from '../services/logger.js'

const router = Router()

// 获取可用模型列表
router.get('/list', async (req, res, next) => {
  try {
    const models = await modelService.listModels()
    res.json(models)
  } catch (error) {
    logger.error('Failed to list models:', error)
    next(error)
  }
})

// 测试连接
router.post('/test', async (req, res, next) => {
  try {
    const { endpoint } = req.body
    const result = await modelService.testConnection(endpoint)
    res.json(result)
  } catch (error) {
    logger.error('Failed to test connection:', error)
    next(error)
  }
})

// 拉取模型
router.post('/pull', async (req, res, next) => {
  try {
    const { name } = req.body
    const result = await modelService.pullModel(name)
    res.json(result)
  } catch (error) {
    logger.error('Failed to pull model:', error)
    next(error)
  }
})

export default router 